//
//  SpecialProductsTableViewCell.m
//  Youhuiju
//
//  Created by yutenys on 16/7/21.
//  Copyright © 2016年 yutenys. All rights reserved.
//

#import "SpecialProductsTableViewCell.h"
#import "SpecialCollectionViewCell.h"
@interface SpecialProductsTableViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>


@property (weak, nonatomic) IBOutlet UICollectionView *yhjCollectionView;//collectionView
@property (weak, nonatomic) IBOutlet UIButton *moreBtn;//查看更多
@property (weak, nonatomic) IBOutlet UIImageView *sectionImg;


//适配

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleImgHig;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *moreBtnTrailing;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *moreBtnHig;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *moreBtnWid;

@end

@implementation SpecialProductsTableViewCell

static NSString *SpecialCollectionViewCellIden = @"SpecialCollectionViewCellIden";

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.titleImgHig.constant = 50 * FitH;
    self.moreBtnTrailing.constant = 20 * FitW;
    self.moreBtnHig.constant = 30 * FitH;
    self.moreBtnWid.constant = 50 * FitW;
self.moreBtn.titleLabel.font = [UIFont systemFontOfSize:11 * FitH];
    
    self.yhjCollectionView.delegate = self;
    self.yhjCollectionView.dataSource = self;
    [self.yhjCollectionView registerNib:[UINib nibWithNibName:@"SpecialCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:SpecialCollectionViewCellIden];
    
    
}


-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
//    return self.dataSource.count;
    return 6;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 1 || indexPath.row == 4)
    {
        return CGSizeMake(125 * FitW, 144 * FitH);
    }
    return CGSizeMake(124 * FitW, 144 * FitH);
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    SpecialCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:SpecialCollectionViewCellIden forIndexPath:indexPath];
    
//    NSArray *arr = @[@"mz1",@"mz2",@"mz3",@"mz4",@"mz5",@"mz6"];
//
//    cell.goodsImg.image = [UIImage imageNamed:arr[indexPath.row]];
    cell.goodsImg.image = LoadImage(@"meizhuangZW");
    cell.goodModel = self.dataSource[indexPath.row];

    return cell;
}

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 1 * FitW;
}

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 1 * FitH;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
//    DLog(@"这是第%ld个",indexPath.row);
    [self.clickedCellJumpDelegate specialClickedCellJump:[self.dataSource[indexPath.row] good_detailAPI]];
}
- (IBAction)moreBtnClickedAction:(UIButton *)sender {
    if (self.moreBtnClickHandler)
    {
        self.moreBtnClickHandler();
    }
}

-(void)setDataSource:(NSArray *)dataSource
{
    if (_dataSource != dataSource)
    {
        _dataSource = dataSource;
        
        [_yhjCollectionView reloadData];
    }
}

#pragma amrk --- setter
-(void)setImgUrl:(NSString *)imgUrl
{
    if (_imgUrl != imgUrl)
    {
        _imgUrl = imgUrl;
        
        self.sectionImg.image = LoadImage(imgUrl);
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}




@end
